Package com.netscape.certsrv.util
Class AsyncLoader
java.lang.Object
com.netscape.certsrv.util.AsyncLoader
A locking mechanism for loading or reloading an initially
unknown number of items.
The "producer" is the thread that loads items, informing the
Loader when each item is loaded and how many items there are
(when that fact becomes known).
Other threads can await the completion of a (re)loading
process.
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncLoader
(int timeoutSeconds) Create an AsyncLoader with the specified timeout. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Wait upon the consumer to finish loading items.void
Increment the number of items loaded by 1.void
Set the number of items.void
shutdown()
void
Acquire the lock as a producer and reset progress-tracking variables.
-
Constructor Details
-
AsyncLoader
public AsyncLoader(int timeoutSeconds) Create an AsyncLoader with the specified timeout. If timeoutSeconds > 0, startLoading() will start a timer that will forcibly unlock the loader after the specified timeout.
-
-
Method Details
-
startLoading
public void startLoading()Acquire the lock as a producer and reset progress-tracking variables. -
increment
public void increment()Increment the number of items loaded by 1. If the number of items is known and that many items have been loaded, unlock the loader. If the loader is not currently loading, does nothing. -
setNumItems
Set the number of items. If the number of items already loaded is equal to or greater than the number, unlock the loader. -
awaitLoadDone
Wait upon the consumer to finish loading items.- Throws:
InterruptedException
- if the thread is interrupted while waiting for the loading lock. This can happen due to timeout.
-
shutdown
public void shutdown()
-